#include <iostream>
#include <string>
#include <algorithm>
#include <memory>
using namespace std;
namespace my_MemoryPool
{
    template <typename T>
    class FixedMemoryPool
    {
    public:
        T *New()
        {
            T* ret = nullptr;
            if (_list != nullptr)
            {
                ret = (T *)_list;
                _list = *(void **)_list;
            }
            else
            {
                int objSize = max(sizeof(T), sizeof(void *));
                if (_sumSize < objSize)
                {
                    _mem = (char *)malloc(128 * 1024);
                    _sumSize = 128 * 1024;
                }
                ret = (T *)_mem;
                _mem += objSize;
                _sumSize -= objSize;
            }
            new (ret) T;
            return ret;
        }
        void Delete(T *p)
        {
            p->~T();
            *(void **)p = _list;
            _list = p;
        }
    private:
        size_t _sumSize = 0;
        char *_mem = nullptr;
        void *_list = nullptr;

    };
}